#ifndef __HEALPIX_DATA_H
#define __HEALPIX_DATA_H

#include <iostream>
#include <vector>

#include "DataContainer.h"
#include "fitsio.h"
#define HEALPIX_NULLVAL (-1.6375e30)

using namespace std;

extern "C" {

	int ang2pix_ring(const long, double, double, long *);
	int pix2ang_ring(long nside, long ipix, double *theta, double *phi);
}

typedef struct healpix_value {

	int pixel;
	float value[4];
	float weight[4];

} healpix_t;

class HEALPIX_Data : public DataContainer {

	private:

	int nside;
	int poln;

	vector<healpix_t> data;

	public:
	/* pixnum is not the HEALPIX index but the index into the current data */
	void set_poln(int pol) {poln = pol;};
	void add_point(float ra,float dec, float val, float sigma);
	int Get_Sky_Val(float ra, float dec, vector<float>& values);
	int Get_Pix_Val(int pixnum, vector<float>& values);
	int Get_Pix_Vertices(int pixnum, vector<float>& point, vector<float>& vertices);
	void Get_Val_Limits(vector<float> &limits);
	int load();
	int load_cut4(fitsfile *, int);
	void Scale(float factor);

	float get_mean();
	float get_rms();

	HEALPIX_Data(char *);
	HEALPIX_Data();
	~HEALPIX_Data();

};
#endif	
